package cn.gson.crmdemo.controller.sale;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.service.ComplaintService;
import cn.gson.crmdemo.model.vo.ComplaintCustomerVo;
import cn.gson.crmdemo.model.vo.QuoSaleCusProVo;

@Controller
public class ComplaintController {

	@Autowired
	ComplaintService cs;
	/**
	 * 查所有投诉
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("com-All")
	@ResponseBody
	public Map<String, Object> selectComAll(@RequestParam("page") Integer pageNum,
			@RequestParam("pageSize") Integer pageSize) {
		Page<Object> page = PageHelper.startPage(pageNum, pageSize);
		// 当前页的内容
		JSONArray list = cs.selectComplaint();
		// 总记录数
		long total = page.getTotal();
		Map<String, Object> map = new HashMap<>();
		map.put("list", list);
		map.put("total", total);
		return map;
	}
	
	/**
	 * 添加报价单
	 * 
	 * @param sales
	 * @return
	 */
	@RequestMapping("add-com")
	public String addCom(ComplaintCustomerVo complaint) {
	
		cs.addCom(complaint);
		// 重定向到查询页面
		return "redirect:com-All?page=1&pageSize=7";
	}
	/**
	 * 修改报价单
	 * 
	 * @param sales
	 * @return
	 */
	@RequestMapping("update-com")
	public String updateCom(ComplaintCustomerVo complaint) {
		System.err.println(":::::::::::::::complaintid修改:::::" + complaint.getComplaintId());
	
		cs.updateCom(complaint);
		// 重定向到查询页面
		return "redirect:com-All?page=1&pageSize=7";
	}
	
	/**
	 * 根据id查询报价单
	 * 
	 * @param salesId
	 * @return
	 */
	@RequestMapping("complaint-id")
	@ResponseBody
	public JSONArray selectcomplaintId(Integer complaintId) {
		System.err.println("id:=====================" + complaintId);
		// 当前页的内容
		JSONArray list = cs.selectComplaintId(complaintId);
		return list;
	}
	
	@RequestMapping("value-All")
	@ResponseBody
	public Map<String, Object> selectValue(@RequestParam("page") Integer pageNum,
			@RequestParam("pageSize") Integer pageSize,int value) {
		
		Page<Object> page = PageHelper.startPage(pageNum, pageSize);
		// 当前页的内容
		JSONArray list = cs.selectValue(value);
		// 总记录数
		long total = page.getTotal();
		Map<String, Object> map = new HashMap<>();
		map.put("list", list);
		map.put("total", total);
		return map;
	}
	
	/**
	 * 客户模糊查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
		@RequestMapping("com-select")
		@ResponseBody
		public Map<String, Object> selectMoHuComplaintName(@RequestParam("page") Integer pageNum,
				@RequestParam("pageSize") Integer pageSize,String complaintTheme) {
			Page<Object> page = PageHelper.startPage(pageNum, pageSize);
			// 当前页的内容
			JSONArray list = cs.selectMoHuComplaintName(complaintTheme);
			System.err.println("=====================cus"+complaintTheme);
			// 总记录数
			long total = page.getTotal();
			Map<String, Object> map = new HashMap<>();
			map.put("list", list);
			map.put("total", total);
			return map;
		}
		
		// 增删改之后，一定要重定向到查询的接口
		@RequestMapping("del-com")
		public String delquo(Integer complaintId) {
			System.err.println("complaintId"+complaintId);
			cs.updateStatus2(complaintId);
			return "redirect:com-All?page=1&pageSize=7";
		}

}
